import {
  saveIndicator, listIndicator, deleteIndicator,
  saveAbility, listAbility, deleteAbility,
  saveJob, listJob, deleteJob,
} from '@/services/RadarChartService';


const RadarCharModel = {
  namespace: 'radarCharModel',
  state: {
    indicator: [],
    ability: [],
    job: [],
  },
  effects: {
    * listIndicator({payload}, {call, put}) {
      const response = yield call(listIndicator, payload);

      yield put({
        type: 'listIndicatorRes',
        payload: response,
      });
    },
    * saveIndicator({payload}, {call, put}) {
      const response = yield call(saveIndicator, payload);
      yield put({
        type: 'saveIndicatorRes',
        payload: response,
      });
    },
    * deleteIndicator({payload}, {call, put}) {
      const response = yield call(deleteIndicator, payload);
      yield put({
        type: 'deleteIndicatorRes',
        payload: response,
      });
    },
    * listAbility({payload}, {call, put}) {
      const response = yield call(listAbility, payload);
      yield put({
        type: 'listAbilityRes',
        payload: response,
      });
    },
    * saveAbility({payload}, {call, put}) {
      const response = yield call(saveAbility, payload);
      yield put({
        type: 'saveAbilityRes',
        payload: response,
      });
    },
    * deleteAbility({payload}, {call, put}) {
      const response = yield call(deleteAbility, payload);
      yield put({
        type: 'deleteAbilityRes',
        payload: response,
      });
    },
    * listJob({payload}, {call, put}) {
      const response = yield call(listJob, payload);
      yield put({
        type: 'listJobRes',
        payload: response,
      });
    },
    * saveJob({payload}, {call, put}) {
      const response = yield call(saveJob, payload);
      yield put({
        type: 'saveJobRes',
        payload: response,
      });
    },
    * deleteJob({payload}, {call, put}) {
      const response = yield call(deleteJob, payload);
      yield put({
        type: 'deleteJobRes',
        payload: response,
      });
    }


  },
  reducers: {
    saveIndicatorRes(state, {payload}) {
      return {...state};
    },
    deleteIndicatorRes(state, {payload}) {
      state.indicator.push(payload);
      return {...state};
    },
    listIndicatorRes(state, {payload}) {
      state.indicator = payload.slice();
      return {...state};
    },
    saveAbilityRes(state, {payload}) {
      return {...state};
    },
    deleteAbilityRes(state, {payload}) {
      state.ability.push(payload);
      return {...state};
    },
    listAbilityRes(state, {payload}) {
      state.ability = payload.slice();

      return {...state};
    },
    saveJobRes(state, {payload}) {
      return {...state};
    },
    deleteJobRes(state, {payload}) {
      state.job.push(payload);
      return {...state};
    },
    listJobRes(state, {payload}) {
      state.job = payload.slice();

      return {...state};
    }


  },
}

export default RadarCharModel;
